<template>
	<view class="con">
		<!-- <view class="top flex flex_between">
			<view class="topz">到账方式</view>
			<view class="topy flex">
				<view class="topy1">支付宝({{userInfo.zfb}})</view>
				<image class="topy2" src="/static/jiant.png" mode="widthFix"></image>
			</view>
		</view> -->
		<view class="mian">
			<view class="mian_t flex flex_between">
				<view>结算金额</view>
				<view @click="withdrawalAll">全部</view>
			</view>
			<view class="mian_m flex">
				<view class="mian_m1">￥</view>
				<input class="mian_m2" v-model="money" type="number" placeholder="请输入结算金额"/>
			</view>
			<view class="mian_b">可结算(元)<text>{{userInfo.money}}</text></view>
		</view>
		<view class="sureBtn" @click="withdrawSaveFun">确认结算</view>
	</view>
	
</template>

<script>
  import {
    withdrawSave //结算
  } from '@/request/api.js'
	export default {
		data() {
			return {
				openid:uni.getStorageSync('openid'),
				userInfo: uni.getStorageSync('userInfo'), //授权后的信息
        money:'' //需要结算的钱
			};
		},
    onLoad() {
      
    },
    methods:{
      // 点击全部
      withdrawalAll(){
        this.money = this.userInfo.money
      },
      // 结算
      withdrawSaveFun(){
        console.log('金额')
        console.log(this.money)
        if(this.money<1){
          uni.showToast({
          	icon: 'none',
          	title: '低于金额不能低于1元'
          })
          return
        }
        
        let param = {
          openid:this.openid,
          money:this.money
        }
        if(this.money<=0 || this.money===''){
          uni.showToast({
            icon: 'none',
            title: '请输入正确的结算金额'
          })
          return
        }
        withdrawSave(param).then(res=>{
          console.log('进行结算')
          console.log(res)
          if(res.error_code === 0){
            uni.showToast({
              icon: 'none',
              title: res.msg
            })
            this.money = ''
            // 返回前一个页面
          }else{
            uni.showToast({
              icon: 'none',
              title: res.msg
            })
          }
          setTimeout(function(){
            uni.navigateBack({
                delta: 1 // 默认值是1，表示返回的页面层数
            });
          },500)
        })
        
      }
      
    }
	}
</script>

<style lang="scss">
.top{
	width: 100%;
	height: 104rpx;
	border-radius: 20rpx;
	background-color: rgba(255,255,255,1);
	padding: 0 30rpx;
	box-sizing: border-box;
	margin-bottom: 20rpx;
	.topz{
		color: rgba(16,16,16,1);
		font-size: 28rpx;
	}
	.topy{
		color: rgba(16,16,16,1);
		font-size: 28rpx;
		.topy2{
			width: 32rpx;
			margin-left: 14rpx;
		}
	}
}
.mian{
	width: 100%;
	height: auto;
	border-radius: 20rpx;
	background-color: rgba(255,255,255,1);
	padding: 30rpx;
	box-sizing: border-box;
	.mian_t{
		color: rgba(16,16,16,1);
		font-size: 28rpx;
		margin-bottom: 20rpx;
	}
	.mian_m{
		width: 100%;
		height: auto;
		height: 90rpx;
		line-height: 90rpx;
		font-family: 'AvantGardeFont';
		.mian_m1{
			color: rgba(16,16,16,1);
			font-size: 60rpx;
			height: 90rpx;
			line-height: 90rpx;
		}
		.mian_m2{
			color: rgba(0,0,0,1);
			font-size: 48rpx;
			height: 90rpx;
			line-height: 90rpx;
		}
	}
	.mian_b{
		color: rgba(16,16,16,1);
		font-size: 28rpx;
		padding-top: 24rpx;
		border-top: 2rpx solid rgba(211,211,211,1);
		margin-top: 40rpx;
		text{
			font-family: 'AvantGardeFont';
			margin-left: 20rpx;
		}
	}
}
.sureBtn{
	width: 100%;
	height: 84rpx;
	line-height: 84rpx;
	border-radius: 20rpx;
	background-color: rgba(249,191,65,1);
	color: rgba(16,16,16,1);
	font-size: 32rpx;
	margin-top: 40rpx;
	text-align: center;
}
</style>
